#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import sys, datetime
import pandas as pd
import numpy as np
# import xlsxwriter
# from scipy.optimize import minimize
# from scipy.optimize import Bounds
# import scipy.optimize as opt



from xpy3lib.XRetryableQuery import XRetryableQuery
from xpy3lib.XRetryableSave import XRetryableSave
from model.AbstractDPJob import AbstractDPJob


class DEFECTJob(AbstractDPJob):


    def __init__(self,
                 p_config=None,
                 p_db_conn_mpp=None):


        super(DEFECTJob, self).__init__(p_config=p_config,
                                        p_db_conn_mpp=p_db_conn_mpp,
                                        p_db_conn_rds=None,
                                        p_db_conn_dbprod7=None,
                                        p_unit=None,
                                        p_account=None,
                                        p_cost_center=None,
                                        p_account_period_start=None,
                                        p_account_period_end=None)
        #传入的查询参数，格式魏('','','')可能是单选出来的，可能是多选出来的
        #机组可能和别的处理逻辑要不同
        #self.seal_code = p_seal_code
        #缺陷代码
        #self.unit_code = p_unit_code
        #机组代码
        #self.prod_class_code = p_prod_class_code
        #品种大类
        #self.apn = p_apn
        #产品用途
        #self.tapping_mark = p_tapping_mark
        #出钢记号
        #self.sg_std = p_sg_std
        #牌号
        #self.order_thick = p_order_thick
        #合同厚度
        #self.order_width = p_order_width
        #合同宽度
        #self.sg_sign = p_sg_sign
        #钢级代码
        #self.order_no = p_order_no
        #合同号
        #self.fin_cust_code = p_fin_cust_code
        #最终用户


        pass


    def execute(self):
        return self.do_execute()


    def do_execute(self):

        super(DEFECTJob, self).do_execute()
        start = datetime.datetime.now()
        p_day_1 = (start - datetime.timedelta(days=1)).strftime("%Y%m%d")
        p_day_2 = (start - datetime.timedelta(days=2)).strftime("%Y%m%d")
        p_day_3 = (start - datetime.timedelta(days=90)).strftime("%Y%m%d")
        # p_day_1 = '20211103'
        # p_day_2 = '20211102'
        start_time = p_day_2 + '000000'
        end_time = p_day_1 + '000000'
        three_month = p_day_3 + '000000'
        # start_time = '20211121000000'
        # end_time = '20211122000000'
        #three_month = '20210901000000'




        sql = " with tmp as (select * from (   " \
              " select WP_RELATIVE_COMBINE_CODE,MAT_TRACK_NO,MAT_ACTUAL_WT,WP_UNIT_ROUTE_COMBINE_DESC,  " \
              " ENTRY_MAT_NO,EXIT_MAT_NO,UNIT_CODE,PRODUCE_END_TIME,  " \
              " MAT_ACTUAL_THICK,MAT_ACTUAL_WIDTH,MAT_ACTUAL_LENGTH ,MAT_SEQ_NO,ORDER_NO as ORDER_NO_TREE,TAPPING_MARK,MAT_STATUS_CODE  " \
              " ,rank() over(partition by MAT_TRACK_NO order by MAT_SEQ_NO desc) as RANK " \
              " from BGTAMSZZQM.T_DWD_FACT_ZZQM_MATERIAL_TREE  " \
              " ) where RANK=1 and LEFT(UNIT_CODE,1)='C') " \
              " select t11.*, " \
              " t3.HR_PLAN_NO,t3.CAST_NO,t3.SLAB_NO,t3.SM_PRODTIME, " \
              " t5.FIN_CUST_CODE as FIN_CUST_CODE_OUTPUT,t5.ORDER_THICK as ORDER_THICK_OUTPUT,t5.ORDER_WIDTH as ORDER_WIDTH_OUTPUT,t5.ORDER_LEN_MIN,t5.SORT_GRADE_CODE_F,t5.SG_SIGN as SG_SIGN_OUTPUT" \
              " ,t7.HOLD_CODE,t7.RMA_DESC,t7.HOLD_DESC_1,t7.HOLD_DESC_2,t7.HOLD_DESC_3,t7.HOLD_DESC_4,t7.HOLD_DESC_5,t7.DEFECT_DESC,t7.REPAIR_TYPE " \
              " ,t8.HT_NO,t8.CC_MACH_NO,MAX(NVL(t9.STOCK_NO,''),NVL(t10.STOCK_NO,'')) as STOCK_NO,t6.MATERIAL_WEIGHT,t6.QM_TYPE,t6.DEFECT_CODE as EXIT_COIL_DEFECT_CODE,t6.DEFECT_DESC_NEW,t6.QM_REASON " \
              " ,t20.HOLD_CAUSE_CODE as DEFECT_CODE,t21.DEFECT_CNAME as DEFECT_NAME " \
              " from ( " \
              " select c.* ,d.WP_RELATIVE_COMBINE_CODE,d.MAT_TRACK_NO,d.MAT_ACTUAL_WT,d.WP_UNIT_ROUTE_COMBINE_DESC,d.ORDER_NO_TREE as ORDER_NO_OUTPUT,d.TAPPING_MARK,d.MAT_STATUS_CODE" \
              " from ( " \
              " select t1.*,t2.EXIT_MAT_NO,t2.PONO,t2.APN as APN_OUTPUT" \
              " from ( " \
              " select ORDER_NO as ORDER_NO_INPUT,CONTRACT_CONFIRM_TIME,PROD_CLASS_CODE, " \
              " APN as APN_INPUT,SG_STD,ORDER_THICK as ORDER_THICK_INPUT,ORDER_WIDTH as ORDER_WIDTH_INPUT,SG_SIGN as SG_SIGN_INPUT,FIN_CUST_CODE as FIN_CUST_CODE_INPUT " \
              " from OMPO.TOM01 " \
              " where CONTRACT_CONFIRM_TIME between '%s' and '%s' " \
              " )as t1 " \
              " left join ( " \
              " select distinct EXIT_MAT_NO,PONO,ORDER_NO as ORDER_NO_INPUT,APN  " \
              " from BGTAMSZZQM.T_DWD_FACT_ZZQM_MM01_INFO " \
              " )as t2 " \
              " on t1.ORDER_NO_INPUT=t2.ORDER_NO_INPUT) c, " \
              " tmp d " \
              " where c.EXIT_MAT_NO=d.EXIT_MAT_NO  " \
              " ) as t11 " \
              " left join " \
              " (select distinct MAT_TRACK_NO,HR_PLAN_NO,CAST_NO,CC_NO,SLAB_NO,SM_PRODTIME,SM_UNIT_NO from BGTAMAQA.T_ADS_FACT_PCDPF_INTEGRATION_INFO ) " \
              " as t3" \
              " on t11.MAT_TRACK_NO = t3.MAT_TRACK_NO " \
              " left join " \
              " BGTAMSZZ00.T_DWD_FACT_ZZPM_ORDER_INFO " \
              " as t5 " \
              " on  t11.ORDER_NO_OUTPUT = t5.ORDER_NO " \
              " left join " \
              " (select distinct OUT_MAT_NO,HOLD_CODE,RMA_DESC,HOLD_DESC_1,HOLD_DESC_2,HOLD_DESC_3,HOLD_DESC_4,HOLD_DESC_5,DEFECT_DESC,REPAIR_TYPE " \
              " from  MMCR.TMMCR1071) as t7 " \
              " on t11.EXIT_MAT_NO=t7.OUT_MAT_NO " \
              " left join " \
              " BGTAMSZZ00.T_DWD_FACT_ZZMM_SM_ML_INFO as t8 " \
              " on t3.CAST_NO = t8.CAST_NO " \
              " and t3.CC_NO =t8.CC_NO " \
              " and t11.PONO =t8.PONO " \
              " left join " \
              " (select MAT_NO as EXIT_MAT_NO, STOCK_NO from MMCR.TMMCR01 " \
              " where PROD_END_TIME>='%s' " \
              " )as t9 " \
              " on t11.EXIT_MAT_NO = t9.EXIT_MAT_NO " \
              " left join " \
              " (select MAT_NO as EXIT_MAT_NO, STOCK_NO from MMCR.HMMCR01  " \
              " where PROD_END_TIME>='%s' " \
              " )as t10 " \
              " on t11.EXIT_MAT_NO = t10.EXIT_MAT_NO " \
              " left join " \
              " (select  " \
              " MAT_NO as EXIT_MAT_NO,MATERIAL_WEIGHT,QM_TYPE,SEAL_CODE as DEFECT_CODE,DEFECT_DEC as DEFECT_DESC_NEW,QM_REASON " \
              " from BGTAMSZZ00.T_DWD_FACT_ZZCH_MM_DEFECT_TOTAL where " \
              " QM_LABEL_TYPE='计入' and PRODUCT_FACTORY<>'宝森' " \
              " and QM_TYPE in ('报废','报次','降级') " \
              " and SEAL_CODE is not null) as t6  " \
              " on t11.EXIT_MAT_NO= t6.EXIT_MAT_NO  " \
              " left join BGTAMSZZ00.T_DWD_FACT_ZZMM_CR_HOLD_INFO as t20  " \
              " on t11.EXIT_MAT_NO= t20.OUT_MAT_NO  " \
              " left join BGTAMSZZ00.T_DWD_DIM_ZZMM_DEFECT as t21   " \
              " on right(t20.HOLD_CAUSE_CODE,2) =t21.DEFECT_CODE "  % (start_time,end_time,three_month,three_month)


        print(sql)
        df1 = XRetryableQuery(p_db_conn=self.db_conn_mpp, p_sql=sql, p_max_times=5).redo()
        success = df1.empty is False
        if success is False:
            return
        df1.columns = df1.columns.str.upper()
        print(df1)
        df1['PROC_NAME_NEXT_STEELMAK'] = ''
        df1['UNIT_CODE_NEXT_STEELMAK'] = ''
        df1['PROC_NAME_STEELMAK'] = ''
        df1['EXIT_MAT_NO_STEELMAK'] = ''
        df1['UNIT_CODE_STEELMAK'] = ''
        df1['PRODUCE_END_TIME_STEELMAK'] = ''
        df1['MAT_ACTUAL_THICK_STEELMAK'] = 0
        df1['MAT_ACTUAL_WIDTH_STEELMAK'] = 0
        df1['MAT_ACTUAL_LENGTH_STEELMAK'] = 0

        df1['PROC_NAME_NEXT_HR'] = ''
        df1['UNIT_CODE_NEXT_HR'] = ''
        df1['PROC_NAME_HR'] = ''
        df1['EXIT_MAT_NO_HR'] = ''
        df1['UNIT_CODE_HR'] = ''
        df1['PRODUCE_END_TIME_HR'] = ''
        df1['MAT_ACTUAL_THICK_HR'] = 0
        df1['MAT_ACTUAL_WIDTH_HR'] = 0
        df1['MAT_ACTUAL_LENGTH_HR'] = 0

        df1['PROC_NAME_NEXT_HDL'] = ''
        df1['UNIT_CODE_NEXT_HDL'] = ''
        df1['PROC_NAME_HDL'] = ''
        df1['EXIT_MAT_NO_HDL'] = ''
        df1['UNIT_CODE_HDL'] = ''
        df1['PRODUCE_END_TIME_HDL'] = ''
        df1['MAT_ACTUAL_THICK_HDL'] = 0
        df1['MAT_ACTUAL_WIDTH_HDL'] = 0
        df1['MAT_ACTUAL_LENGTH_HDL'] = 0

        df1['PROC_NAME_NEXT_PICKLING'] = ''
        df1['UNIT_CODE_NEXT_PICKLING'] = ''
        df1['PROC_NAME_PICKLING'] = ''
        df1['EXIT_MAT_NO_PICKLING'] = ''
        df1['UNIT_CODE_PICKLING'] = ''
        df1['PRODUCE_END_TIME_PICKLING'] = ''
        df1['MAT_ACTUAL_THICK_PICKLING'] = 0
        df1['MAT_ACTUAL_WIDTH_PICKLING'] = 0
        df1['MAT_ACTUAL_LENGTH_PICKLING'] = 0

        df1['PROC_NAME_NEXT_MILL'] = ''
        df1['UNIT_CODE_NEXT_MILL'] = ''
        df1['PROC_NAME_MILL'] = ''
        df1['EXIT_MAT_NO_MILL'] = ''
        df1['UNIT_CODE_MILL'] = ''
        df1['PRODUCE_END_TIME_MILL'] = ''
        df1['MAT_ACTUAL_THICK_MILL'] = 0
        df1['MAT_ACTUAL_WIDTH_MILL'] = 0
        df1['MAT_ACTUAL_LENGTH_MILL'] = 0

        df1['PROC_NAME_NEXT_ANNEAL'] = ''
        df1['UNIT_CODE_NEXT_ANNEAL'] = ''
        df1['PROC_NAME_ANNEAL'] = ''
        df1['EXIT_MAT_NO_ANNEAL'] = ''
        df1['UNIT_CODE_ANNEAL'] = ''
        df1['PRODUCE_END_TIME_ANNEAL'] = ''
        df1['MAT_ACTUAL_THICK_ANNEAL'] = 0
        df1['MAT_ACTUAL_WIDTH_ANNEAL'] = 0
        df1['MAT_ACTUAL_LENGTH_ANNEAL'] = 0

        df1['PROC_NAME_NEXT_HOTDIP'] = ''
        df1['UNIT_CODE_NEXT_HOTDIP'] = ''
        df1['PROC_NAME_HOTDIP'] = ''
        df1['EXIT_MAT_NO_HOTDIP'] = ''
        df1['UNIT_CODE_HOTDIP'] = ''
        df1['PRODUCE_END_TIME_HOTDIP'] = ''
        df1['MAT_ACTUAL_THICK_HOTDIP'] = 0
        df1['MAT_ACTUAL_WIDTH_HOTDIP'] = 0
        df1['MAT_ACTUAL_LENGTH_HOTDIP'] = 0

        df1['PROC_NAME_NEXT_EP'] = ''
        df1['UNIT_CODE_NEXT_EP'] = ''
        df1['PROC_NAME_EP'] = ''
        df1['EXIT_MAT_NO_EP'] = ''
        df1['UNIT_CODE_EP'] = ''
        df1['PRODUCE_END_TIME_EP'] = ''
        df1['MAT_ACTUAL_THICK_EP'] = 0
        df1['MAT_ACTUAL_WIDTH_EP'] = 0
        df1['MAT_ACTUAL_LENGTH_EP'] = 0

        df1['PROC_NAME_NEXT_CRFS'] = ''
        df1['UNIT_CODE_NEXT_CRFS'] = ''
        df1['PROC_NAME_CRFS'] = ''
        df1['EXIT_MAT_NO_CRFS'] = ''
        df1['UNIT_CODE_CRFS'] = ''
        df1['PRODUCE_END_TIME_CRFS'] = ''
        df1['MAT_ACTUAL_THICK_CRFS'] = 0
        df1['MAT_ACTUAL_WIDTH_CRFS'] = 0
        df1['MAT_ACTUAL_LENGTH_CRFS'] = 0



        #df1到此得到了狠得多材料号MAT_NO,材料跟踪号MAT_TRACK_NO
        #WP_RELATIVE_COMBINE_CODE血缘码，判断位数，假设010101010101，是12位，那么他的第一个工序对应的血缘码就是01，第二道对应的就是0101，第五道对应的就是0101010101
        #对每一行进行循环
        for index_df1, row_df1 in df1.iterrows():
            tmp_WP_RELATIVE_COMBINE_CODE = df1.loc[index_df1, 'WP_RELATIVE_COMBINE_CODE']
            tmp_MAT_TRACK_NO = df1.loc[index_df1, 'MAT_TRACK_NO']

            #tmp_WP_RELATIVE_COMBINE_CODE = '010203040506'
            print(f'血缘码WP_RELATIVE_COMBINE_CODE:{tmp_WP_RELATIVE_COMBINE_CODE}')
            print('-----------------------------------------')
            # NOTE 一道工序占两位
            MY_FIXED_PROCESS_WIDTH = 2
            my_start = 0
            my_end = 0
            process_index = 0
            b = ''
            # NOTE 找父工序时，不要带上自己.  假如是0101010102. 那就只要前四道工序(即只要01010101，不要02)
            while my_end < len(tmp_WP_RELATIVE_COMBINE_CODE) - MY_FIXED_PROCESS_WIDTH:
                my_end += MY_FIXED_PROCESS_WIDTH
                process_index += 1
                process_blood_code = tmp_WP_RELATIVE_COMBINE_CODE[my_start:my_end]
                print(f'第{process_index}道工序, {process_blood_code}')
                b = f"{b}'{process_blood_code}',"

            print('-----------------------------------------')

            b = b.strip(',')
            b = '(' + b + ')'
            #print(b)
            # 对每一行进行查询下列SQL，并按照要求补充到每一行的后面

            sql = " select MAT_SEQ_NO,WP_RELATIVE_COMBINE_CODE,MAT_TRACK_NO, " \
                  " ENTRY_MAT_NO,EXIT_MAT_NO,UNIT_CODE,PRODUCE_END_TIME,  " \
                  " MAT_ACTUAL_THICK,MAT_ACTUAL_WIDTH,MAT_ACTUAL_LENGTH " \
                  " ,case when unit_code in ('S001','S002','S005','S3LF','S003','S004','S006','S02A','S02B') then '炼钢'   " \
                  " when unit_code in  ('H031','H032','H033','H038') then '热轧'  " \
                  " when unit_code in  ('H067','H048','H076','H077','H042','H045','H110','H305') then '热轧精整' " \
                  " when unit_code in  ('C101', 'C401') then '酸洗工序' " \
                  " when unit_code in  ('C102', 'C202', 'C502','C602','C302') then '轧机工序' " \
                  " when unit_code in  ('C103', 'C112', 'C212','C312','C512','C612','C412') then '退火工序' " \
                  " when unit_code in  ('C108', 'C208', 'C308','C608','C708','CA08','C408','C508') then '热镀工序' " \
                  " when unit_code in  ('C111', 'C211', 'C311','C217','C317','C117','C808') then '电镀工序' " \
                  " when unit_code in  ('C171', 'C172', 'C175','C176','C470','C471','C472','C160','C161','C162','C260','C173','C270','C271','C272','C273','C850','C851','C860','C861','C862','C150','C151','C152','C154','C155','C250','C251','C252','C253','C254') then '精整工序' " \
                  " when unit_code in  ('C109', 'C209','C309','C216','C409') then '彩涂' " \
                  " when unit_code in  ('C116', 'C216') then '准备' " \
                  " when unit_code in  ('C122') then '中试' " \
                  " when unit_code in  ('C137') then '脱脂' " \
                  " when unit_code in  ('C290') then '手工分选' " \
                  " when unit_code in  ('C204','C104') then '平整' " \
                  " end as PROC_NAME " \
                  " from BGTAMSZZQM.T_DWD_FACT_ZZQM_MATERIAL_TREE " \
                  " where WP_RELATIVE_COMBINE_CODE in %s " \
                  " and MAT_TRACK_NO = '%s' " \
                  " order by WP_RELATIVE_COMBINE_CODE " % (b, tmp_MAT_TRACK_NO)
            print(sql)
            df2 = XRetryableQuery(p_db_conn=self.db_conn_mpp, p_sql=sql, p_max_times=5).redo()
            success = df2.empty is False
            if success is False:
                return
            df2.columns = df2.columns.str.upper()
            #print(df2)
            df22 = df2.shift(-1)
            df2 = df2.reset_index()
            df22 = df22.reset_index()
            df22.drop(['MAT_SEQ_NO'], axis=1, inplace=True)
            df22.drop(['WP_RELATIVE_COMBINE_CODE'], axis=1, inplace=True)
            df22.drop(['MAT_TRACK_NO'], axis=1, inplace=True)
            df22.drop(['ENTRY_MAT_NO'], axis=1, inplace=True)
            df22.drop(['EXIT_MAT_NO'], axis=1, inplace=True)
            df22.drop(['PRODUCE_END_TIME'], axis=1, inplace=True)
            df22.drop(['MAT_ACTUAL_THICK'], axis=1, inplace=True)
            df22.drop(['MAT_ACTUAL_WIDTH'], axis=1, inplace=True)
            df22.drop(['MAT_ACTUAL_LENGTH'], axis=1, inplace=True)
            df22.rename(columns={'PROC_NAME': 'PROC_NAME_NEXT'}, inplace=True)
            df22.rename(columns={'UNIT_CODE': 'UNIT_CODE_NEXT'}, inplace=True)

            df2 = pd.concat([df2, df22], axis=1)


            properties_all = df2.columns.tolist()
            # '炼钢'， '热轧','热轧精整','酸洗工序','轧机工序','退火工序','热镀工序','电镀工序','精整工序' 9道工序
            PROPERTIES_7 = ['PROC_NAME',
                      'EXIT_MAT_NO',
                      'UNIT_CODE',
                      'PRODUCE_END_TIME',
                      'MAT_ACTUAL_THICK',
                      'MAT_ACTUAL_WIDTH',
                      'MAT_ACTUAL_LENGTH','UNIT_CODE_NEXT','PROC_NAME_NEXT']
            diffs = list(set(properties_all).difference(set(PROPERTIES_7)))

            GXS = [{'name': '炼钢', 'suffix': '_STEELMAK'},
                   {'name': '热轧', 'suffix': '_HR'},
                   {'name': '热轧精整', 'suffix': '_HDL'},
                   {'name': '酸洗工序', 'suffix': '_PICKLING'},
                   {'name': '轧机工序', 'suffix': '_MILL'},
                   {'name': '退火工序', 'suffix': '_ANNEAL'},
                   {'name': '热镀工序', 'suffix': '_HOTDIP'},
                   {'name': '电镀工序', 'suffix': '_EP'},
                   {'name': '精整工序', 'suffix': '_CRFS'}]
            for gx in GXS:
                # NOTE 文件里就是酸洗工序干了三次， 怎么才能只输出一条输出最后一条就是血缘码长的那个。WP_RELATIVE_COMBINE_CODE最大
                df2_LG = df2[df2['PROC_NAME'] == gx['name']]

                if df2_LG.empty is False:
                    df2_LG = df2_LG.sort_values(by=['MAT_SEQ_NO'], ascending=[False]).head(n=1)
                    df2_LG = df2_LG.reset_index()
                # 7列重命名
                    for p in PROPERTIES_7:
                        #print(p)
                        #print(f"{p}{gx['suffix']}")
                        df2_LG.rename(columns={p: f"{p}{gx['suffix']}"}, inplace=True)
                # for p in diffs:
                #     # 删除多余的，不需要和df1合并的那几个属性。不改变内存
                #     df2_LG = df2_LG.drop(p, 1)
                        #print(f"{p}{gx['suffix']}")
                        #print(df2_LG.loc[0, f"{p}{gx['suffix']}"])
                        df1.loc[index_df1, f"{p}{gx['suffix']}"] = df2_LG.loc[0, f"{p}{gx['suffix']}"]
                # df2_LG.drop(['MAT_SEQ_NO'], axis=1, inplace=True)
                # df2_LG.drop(['WP_RELATIVE_COMBINE_CODE'], axis=1, inplace=True)
                # df2_LG.drop(['MAT_TRACK_NO'], axis=1, inplace=True)
                # df2_LG.drop(['GX_NAME'], axis=1, inplace=True)

            # 9道工序，依次拼接到df1的后面 .........
            #     v = ['MAT_TRACK_NO']
            #     df1 = pd.merge(df1, df2_LG, on=v, how='left')
            #     print(df2_LG.loc[0, 'ENTRY_MAT_NO_RZ'])
            # df1.loc[index_df1, 'ENTRY_MAT_NO_LG'] = df2_LG.loc[0, 'ENTRY_MAT_NO_LG']

                
        print('end')
        print(df1)
        df1 = df1.drop_duplicates(keep=False, inplace=False)
        print(df1)
        now = datetime.datetime.now()
        now_1 = now.strftime('%Y%m%d%H%M%S')
        #print(now_1)
        df1['REC_CREATOR'] = 'bgmszz00'
        df1['REC_CREATE_TIME'] = now_1
        sql = " DELETE FROM " \
              " BGTAMSZZ00.T_DWD_FACT_ZZMM_CR_FULL_FLOW_HOLDDEFECT" \
              " WHERE 1=1 " \
              " AND CONTRACT_CONFIRM_TIME >= '%s'" \
              " AND CONTRACT_CONFIRM_TIME < '%s'" % (start_time,end_time)



        self.db_conn_mpp.execute(sql)

        XRetryableSave(p_db_conn=self.db_conn_mpp, p_table_name='T_DWD_FACT_ZZMM_CR_FULL_FLOW_HOLDDEFECT', p_schema='BGTAMSZZ00',
                       p_dataframe=df1,
                       p_max_times=5).redo()
        # df1.rename(columns={'DESCRIPTION': '数据来源'}, inplace=True)
        #
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)
        # df1.drop(['TABLE_ID'], axis=1, inplace=True)

















        # xlsx_name = '测试'
        # xlsx_name = xlsx_name + '.xlsx'
        # print(xlsx_name)
        # writer = pd.ExcelWriter(xlsx_name)
        # df1.to_excel(writer, sheet_name='sheet1')
        # writer.save()
        # 取df2的GX_NAME是'炼钢'的那一行

        # 将ENTRY_MAT_NO,EXIT_MAT_NO,UNIT_CODE,PRODUCE_END_TIME,MAT_ACTUAL_THICK,MAT_ACTUAL_WIDTH,MAT_ACTUAL_LENGTH
        # 在后面加个拼音首字母
        # 改名成ENTRY_MAT_NO_LG,EXIT_MAT_NO_LG,UNIT_CODE_LG,PRODUCE_END_TIME_LG,MAT_ACTUAL_THICK_LG,MAT_ACTUAL_WIDTH_LG,MAT_ACTUAL_LENGTH_LG

        # 然后拼接到df1那一行的后面
        # 如果df2的GX_NAME没有炼钢的那一行，则这几个是空
        # 同理也要拼接'热轧','热轧精整','酸洗工序','轧机工序','退火工序','热镀工序','电镀工序','精整工序'

        #################################
        #下面的都不用看！
#######################################################################################################
